#e
#Title[Bloodthirsty]
#Text[]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\lib_anime_tewi.txt"
	#include_function ".\boss.txt"
	let csd		=GetCurrentScriptDirectory;
	let shotData	=csd ~ ".\shot.txt";
	let imgBoss	=csd ~ "img\dot_tewi.png";
	let imgBG1	=csd ~ "img\maho1.png";
	let imgBG2	=csd ~ "img\maho2.png";
	let BGn		=0;
	let xIni	=GetCenterX;
	let yIni	=GetClipMinY + 100;
	@Initialize {
        CutIn(YOUMU,"Bloodthirsty", "", 0, 0, 0, 0);
        SetLife(2800);
	SetTimer(60);
	SetScore(100000);
	SetDamageRate(5, 5);
	InitializeAction();
	LoadUserShotData(shotData);
	LoadGraphic(imgBoss);
	LoadGraphic(imgBG1);
	LoadGraphic(imgBG2);
        TMain;
	}

	@MainLoop {
	BGn++;
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	yield;
	}

	@DrawLoop {
	SetColor(255,255,255);
	SetGraphicScale(1,1);
	SetAlpha(255);
	SetGraphicAngle(0,0,0);
	DrawBoss(imgBoss);
	BG;
	}

	@Finalize{
	}

function wait(w) {
    loop(w) { yield; }
}
    task TMain {
        yield;
SetDamageRate(100,100);
moveA(90,0);
wait(90);
loop{
shotA(-1,1);
shotA(1,1);
moveA(90,320);
wait(320);
moveA(180,0);
shotB;
moveA(160,0);
wait(160);
shotA(-1,-1);
shotA(1,-1);
moveA(90,320);
wait(320);
moveA(180,0);
shotC;
moveA(160,0);
wait(160);
}


}

task shotA(an,ann){
let A=60;
let B=0;
let C=0;
let D=60;
loop(160){
B=cos(C)*480*ann;
wait(2);
loop(360/A){
CreateShot01(GetX+cos(B)*D,GetY+sin(B)*D,2+cos(C),B+sin(C)+(90*an),22,10);
B+=A;
}
C+=1*an;
}
}

sub shotB{
let B=0;
loop(6){
wait(30);
let A=4;
loop(360/A){
CreateShot01(GetX+cos(B)*40,GetY+sin(B)*40,2,B+90,46,10);
CreateShot01(GetX+cos(B)*40,GetY+sin(B)*40,2,B-90,46,10);
B+=A;
}
}
}

sub shotC{
let A=GetAngleToPlayer;
let C=-180;
loop(90){
wait(2);
let B=A-88;
while(B<A+89){
CreateShot01(GetX+cos(B-C)*40,GetY+sin(B-C)*40,7,B-C,46,5);
CreateShot01(GetX+cos(B+C)*40,GetY+sin(B+C)*40,7,B+C,46,5);
B+=8;
}
if(C>-268){C-=2;}
}
}

   task moveA(wa,waa) {
	wait(waa);
	let wMove =wa;
	SetAction(ACT_MOVE,wMove);
	moveToPlayer(rand(40, 120), rand(-40, 40), wMove,
		GetClipMinX + 48, GetClipMinY +  50,
		GetClipMaxX - 48, GetClipMinY + 120);
	wait(wMove);
	}

function GetGapAngle(
	let x1,
	let y1,
	let x2,
	let y2
){
	return atan2(y2-y1,x2-x1);
}

    function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
        let x;
        let y;
        if(GetPlayerX < GetX) {
            x = GetX - xMove;
            if(x < left) {
                x = GetX + xMove;
            }
        } else {
            x = GetX + xMove;
            if(right < x) {
                x = GetX - xMove;
            }
        }
        y = GetY + yAdd;
        if(y < top) {
            y = top;
        } else if(bottom < y) {
            y = bottom;
        }

        SetMovePosition02(x, y, frame);
    }
}

}